<?php
/**
 * 
 * @author liubin-bt
 * @property Admin_model $Admin_model
 */
class Admin extends Base{
    public function __construct(){
        parent::__construct();
        if( $this->user['group_id'] != 1 ){
            $this->outJsonData(0, '没有权限登录');
        }
        $this->load->model('Admin_model');
    }
    
    public function applyList(){
        $page = intval($this->getSafeRequest('page', 1));
        if( $page > 1000 || $page <= 0 ){
            $page = 1;
        }
        list($count, $list) = $this->Admin_model->getApplyList( $page );
        foreach ($list as &$v){
            $v['type'] = $v['type'] == 1 ? 'Teaser' : 'BP';
        }
        $this->outJsonData(0, ['count'=>$count, 'list'=>$list]);
    }
    
    public function doApply(){
        $apply_id = intval($this->getSafeRequest('apply_id'));
        $status = intval($this->getSafeRequest('status', 1));
        if( !$apply_id ){
            $this->outJsonData(0, '申请id不能为空');
        }
        $this->Admin_model->updateApply(['id'=>$apply_id], ['status'=>$status]);
        
        $this->outJsonData(0, '修改成功');
    }
    
    public function authList(){
        $page = intval($this->getSafeRequest('page', 1));
        if( $page > 1000 || $page <= 0 ){
            $page = 1;
        }
        list($count, $list) = $this->Admin_model->getAuthList( $page );
        $this->outJsonData(0, ['count'=>$count, 'list'=>$list]);
    }
    
    public function doAuth(){
        $id = intval($this->getSafeRequest('id'));
        $status = intval($this->getSafeRequest('status', 1));
        $auth_remark = $this->getSafeRequest('auth_remark', '');
        if( !$id ){
            $this->outJsonData(0, '认证id不能为空');
        }
        $this->Admin_model->updateAuth(['id'=>$id], ['status'=>$status, 'auth_remark'=>$auth_remark]);
        
        $this->outJsonData(0, '修改成功');
    }
}
?>